/* eslint valid-jsdoc: "off" */

'use strict';
const path = require('path');
/**
 * @param {Egg.EggAppInfo} appInfo app info
 */
module.exports = appInfo => {
  const config = exports = {};

  config.keys = `${appInfo.name}_1578313858050_6752`;

  // 默认使用的中间件
  config.middleware = ['accessLog', 'errorHandle'];
  // 模板解析
  config.view = {
    mapping: {
      '.html': 'ejs',
    },
  };
  // session设置
  config.session = {
    maxAge  : 'session', // 关闭浏览器则删除
    key     : 'ZCONNECT',
    httpOnly: true,
    encrypt : true,
  };
  // 静态资源
  config.static = {
    prefix: '/static',
    dir   : [
      path.join(appInfo.baseDir, 'app/public/static'),
      {
        prefix: '/docs',
        dir   : path.join(appInfo.baseDir, '/docs/.vuepress/dist'),
      }],
  };
  // 监听端口
  config.cluster = {
    listen: {
      port: 9100,
    },
  };
  // 邮箱设置
  config.email = {
    client: {
      service         : 'qq',
      secureConnection: true,
      auth            : {
        user: 'xx',
        pass: 'xx',
      },
    },
  };
  // redis
  config.redis = {
    client: {
      host    : '127.0.0.1',
      port    : 6379,
      password: '',
      db      : '0',
    },
    keyPrefix: 'zconnect:',
    agent    : true,
  };
  // 统一错误处理
  config.onerror = {
    all(err, ctx) {
      ctx.body = 'error';
      ctx.status = 500;
    },
    html(err, ctx) {
      // html hander
      ctx.body = '<h3>error</h3>';
      ctx.status = 500;
    },
    json(err, ctx) {
      // json hander
      ctx.body = { message: 'error' };
      ctx.status = 500;
    },
  };
  // 日志集合
  config.logger = {
    appLogName  : 'log.log',
    coreLogName : 'log.log',
    agentLogName: 'log.log',
    errorLogName: 'error.log',
  };
  return {
    ...config,
  };
};
